package com.company.service.impl;

import com.company.entity.xiaosuo;
import com.company.service.BaseService;
import com.company.utils.SericeFactory;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class xiaosuoimpl implements BaseService{


    List list1=new ArrayList();

    public xiaosuoimpl() {
        xiaosuo xiaosuo1=new xiaosuo();
        xiaosuo xiaosuo2=new xiaosuo();
        xiaosuo1.setXv(1);
        xiaosuo1.setName("雪山飞狐");
        xiaosuo1.setZuoze("金庸");
        xiaosuo1.setJianjie("长篇小说");
        list1.add(xiaosuo1);
        xiaosuo2.setXv(2);
        xiaosuo2.setName("顾夏金玉");
        xiaosuo2.setZuoze("顾夏");
        xiaosuo2.setJianjie("短片");
        list1.add(xiaosuo2);
    }

    Scanner sc=new Scanner(System.in);
    @Override
    public void execute(List list) {
       for (;;){

           System.out.println("1.言情 2.武侠");
           int sr= sc.nextInt();
           System.out.println("序号\t名称\t作者\t简介");
           switch (sr){
               case 1:
                   for (int i = 0; i < list1.size(); i++) {
                       xiaosuo x= (xiaosuo)list1.get(i);
                       System.out.println(x.getXv()+"\t"+x.getName()+"\t"+x.getZuoze()+"\t"+x.getJianjie());
                   }
                   System.out.println("---------------小说列表结束---------------");
                   System.out.println("0.返回上一级菜单");
                   System.out.println("1.上传小说");
                   int sr1= sc.nextInt();

                   switch (sr1){
                       case 0:
                           continue;
                       case 1:


                               xiaosuo xiaosuo3=new xiaosuo();
                               xiaosuo3.setXv(list1.size()+1);
                               System.out.println("输入小说名字");
                               xiaosuo3.setName(sc.next());
                               System.out.println("输入作者名字");
                               xiaosuo3.setZuoze(sc.next());
                               System.out.println("输入小说简介");
                               xiaosuo3.setJianjie(sc.next());
                               list1.add(xiaosuo3);
                               try {
                                   File file=new File("C:\\测试\\"+xiaosuo3.getName()+"txt");
                                   file.createNewFile();
                                   System.out.println("上传成功");
                               } catch (IOException e) {
                                   e.printStackTrace();
                               }

                           break;
                   }
                   break;
               case 2:

                   break;
               default:
                   System.out.println("退出");
                   break;
           }
       }
    }


}
